﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace SuspectPhoto
{
    /// <summary>
    /// 
    /// </summary>
    public class CameraConfig
    {
        /// <summary>
        /// 屏幕长宽比
        /// </summary>
        public const double Screen_Scale = 1.31;

        

        public static readonly string Config_File_Name = "CameraConfig.xml";


        public static IList<CameraConfig> Load()
        {
            try
            {
                XElement element = XElement.Load(Config_File_Name);

                IEnumerable<XElement> configs = element.Elements("Camera");

                IList<CameraConfig> ccs = new List<CameraConfig>();

                foreach (XElement el in configs)
                {
                    CameraConfig cc = new CameraConfig();

                    cc.IPAddress=el.Attribute("Ip").Value;
                    cc.Port=(ushort) Convert.ToUInt16(el.Attribute("Port").Value);
                    cc.User = el.Attribute("User").Value;
                    cc.Password = el.Attribute("Password").Value;

                    PhotoRange range = new PhotoRange();

                    range.X1 = Convert.ToInt32(el.Attribute("X1").Value);
                    range.Y1 = Convert.ToInt32(el.Attribute("Y1").Value);
                    range.X2 = Convert.ToInt32(el.Attribute("X2").Value);
                    range.Y2 = Convert.ToInt32(el.Attribute("Y2").Value);

                    cc.InnerRange = range;

                    ccs.Add(cc);
                }

                return ccs;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public string IPAddress { get; set; }

        public ushort Port { get; set; }

        public string User { get; set; }

        public string Password { get; set; }

        public PhotoRange InnerRange { get; set; }

    }
}
